<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<meta charset="UTF-8">

<style type="text/css">
</style>

<title>修改宿管账户密码</title>
</head>
<body>
	<div style="text-align: center;" class="container">
		<div class="row">
			<h3>修改账户密码</h3>
		</div>
		<div class="panel-body">
			<form class="form-horizontal" role="form" id="own_form">
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">请输入旧密码</label>
					<div class="col-sm-10">
						<input type="password" class="form-control" maxlength="20" placeholder="请输入旧密码" name="oldPassword"
							id="input_oldPassword">
					</div>
				</div>
				<!--  -->
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">请输入新密码</label>
					<div class="col-sm-10">
						<input type="password" class="form-control" maxlength="20" placeholder="请输入新密码" name="password00"
							id="input_password00">
					</div>
				</div>
				<!--  -->
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">请再次输入新密码</label>
					<div class="col-sm-10">
						<input type="password" class="form-control" placeholder="请再次输入新密码" maxlength="20" name="password"
							id="input_password">
					</div>
				</div>
				<!--  -->
				<div class="form-group" style="text-align: center;">
					<input type="button" class="btn btn-default" value="OK" id="btn_confirm" style="margin-right: 25px;">
					<!--  -->
					<input type="reset" class="btn btn-default" value="重置" style="margin-left: 25px;">
				</div>
			</form>
		</div>
		<div>
			<a href="ShowOwnProfile.html">返回资料展示页</a>
		</div>
	</div>
</body>
<!--  -->
<script type="text/javascript">
	$('#btn_confirm').on('click', function() {
		var oldPassword = $('#input_oldPassword').val();
		var password00 = $('#input_password00').val();
		var password = $('#input_password').val();

		//校验2次输入之新密是否一致
		if (password00 !== password) {
			alert('2次输入的密码不一致');
			return false;
		}

		//新密码长度必须大于3位
		if (password.length < 3) {
			alert('密码长度至少等于3位');
			return false;
		}

		var url = '/dormitory/HouseParents/revampPasswordHandler';

		$.ajax({
			url : url,
			type : 'POST',
			data : {
				'oldPassword' : oldPassword,
				'password' : password
			},
			dataType : 'json',
			success : function(r) {
				if (r.state === 200) {
					alert('修改密码成功');
					location.href = 'Login.html';
				} else {
					alert(r.message);
				}
			}
		})

	})
</script>
</html>